<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .box {
            width: 400px;
            height: 200px;
            overflow-y: auto;
            border: 1px solid #333;
            margin: 50px auto;
            /* 连续的空白符会被保留。 */
            /* white-space: pre; */
        }
    </style>
</head>

<body>

    <div class="box"></div>
</body>
<script>
    var box = document.getElementsByClassName("box")[0];

    // \s   匹配空白字符  [ \n\r\t\v\f]
    // \S   匹配非空白字符  [^ \n\r\t\v\f]
    var str = "good\ngood\rstudy\t,day day up";

    box.innerHTML = str;



</script>

</html>